package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/product"
	product2 "git.900sui.cn/kc/rpcinterface/interface/product"
	"github.com/streadway/amqp"
)

//修改预警
func main() {
	rpcProduct := new(product.Product).Init()
	defer rpcProduct.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("products.log.updateProductStock"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("products.queue.updateProductStock"), func(msg amqp.Delivery) {
		var args product2.ArgsMqUpdateStock
		json.Unmarshal(msg.Body, &args)
		reply := false
		err := rpcProduct.MqUpdateStock(context.Background(), &args, &reply)
		if err != nil {
			utils.Logerr.Printf("修改商品库存调用错误，args:%v, err:%s", args, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("修改商品库存错误, err: %s", err.Error())
	}
}
